package com.crt.uav.api.v1;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class UavRemoteService {

    private final RestTemplate restTemplate;

    @Value("${uav.system.apiurl}")
    private String uavApiUrl;

    public UavRemoteService(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    public String post(String path, Object body) {
        RequestEntity<Object> request = RequestEntity
                .post(uavApiUrl + path)
                .body(body);
        ResponseEntity<String> response = restTemplate.exchange(request, String.class);
        return response.getBody();
    }

    public String put(String path, Object body) {
        RequestEntity<Object> request = RequestEntity
                .put(uavApiUrl + path)
                .body(body);
        ResponseEntity<String> response = restTemplate.exchange(request, String.class);
        return response.getBody();
    }
}
